package com.yonyou.pmclouds.basecom.exception;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class BusinessRuntimeException extends RuntimeException implements IBusinessFeature {


    private static final long serialVersionUID = 6222272072161959451L;


    private String exCode;
    private Map<String, String> addition;

    public BusinessRuntimeException() {
    }

    public BusinessRuntimeException(String string) {
        super(string);
    }

    public BusinessRuntimeException(String msg, String exCode) {
        super(msg);
        this.exCode = exCode;
    }

    public BusinessRuntimeException(Throwable ex) {
        super(ex);
    }

    public BusinessRuntimeException(String msg, Throwable ex) {
        super(msg, ex);
    }

    public BusinessRuntimeException(String msg, String exCode, Throwable ex) {
        super(msg, ex);
        this.exCode = exCode;
    }

    /**
     * 这里禁掉添加object，避免出现一些不可控的序列化异常
     */
    public void addInfo(String key, String info) {
        if (addition == null) {
            addition = new HashMap<>();
        }
        addition.put(key, info);
    }

    @Override
    public Map<String, String> getAddition() {
        if (addition != null)
            return Collections.unmodifiableMap(addition);
        return addition;
    }

    @Override
    public String getExCode() {
        return exCode;
    }

    public void setExCode(String exCode) {
        this.exCode = exCode;
    }

}
